const dbs = require('./app/core/dbs');
const EventEmitter = require('events');
const eventBus = new EventEmitter();

const moment = require('moment');
const iotLog = require('./app/utils/logUtils');
const iiot = require('./app/iiot');

class AppBootHook {
  constructor(app) {
    this.app = app;
  }

  async configWillLoad() {
    this.app.dbs = new dbs(this.app);
    // eventBus.setMaxListeners(this.app.config.dataBusMaxListeners);
    this.app.eventBus = eventBus;
    this.app.iotLog = new iotLog(this.app);
    this.app.iotLog.logger('SYS START');
    return true;
  }

  async didLoad() {
    return true;
  }

  async willReady() {
    return true;
  }

  async didReady() {

    /**
     * 应用已经启动完毕
     */

    return true;
  }

  async serverDidReady() {
    this.app.iiot = new iiot(this.app);
    return this.app.iiot.restart();
  }
}

module.exports = AppBootHook;
